﻿using MedicalManagementAPP.AccountModule;
using MedicalManagementAPP.Forms.DocForms;
using MedicalManagementAPP.MyException;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MedicalManagementAPP.Forms
{
    public partial class DocForm : Form
    {
        LoginForm loginForm;
        Person user;

        /// <summary>
        /// 以下三个变量用于储存窗体
        /// </summary>
        PatientReceptionForm subPatientForm = null;
        PrescribeMedicineForm subMedicineForm = null;
        InformationMaintenancetForm subManagement = null;
        public DocForm(LoginForm loginForm,Person person)
        {
            InitializeComponent();
            this.IsMdiContainer = true;
            this.loginForm = loginForm;
            this.user = person;
            this.Text = "医生工作窗体  " + person.ToString();
            skinEngine1.SkinFile = @"irisskin2\Wave.ssk";
        }

        private void DocForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            loginForm.Show();
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            string node = navTreeView.SelectedNode.Text;
            switch (node)
            {
                case "返回":
                    this.Close();
                    break;
                default:
                    AdjustForm(GetForm(node));
                    break;
            }
        }

        /// <summary>
        /// 通过需要的窗体名称获取窗体的单例
        /// </summary>
        /// <param name="typeOfForm">输入需要得到的窗体的名称，只可能出现"患者接待" "开药" "处方管理"</param>
        /// <returns>对应的窗体（单例）</returns>
        private Form GetForm(string typeOfForm)
        {
            switch (typeOfForm)
            {
                case "患者接待":
                    if (subPatientForm == null || subPatientForm.IsDisposed)
                    {
                        subPatientForm = new PatientReceptionForm(ref user);
                    }
                    return subPatientForm;
                case "开药":
                    if (subMedicineForm == null || subMedicineForm.IsDisposed)
                    {
                        subMedicineForm = new PrescribeMedicineForm(ref user);
                    }
                    return subMedicineForm;
                case "个人信息维护":
                    if (subManagement == null || subManagement.IsDisposed)
                    {
                        subManagement = new InformationMaintenancetForm(ref user);
                    }
                    return subManagement;
                default:
                    throw new FormNotExist(typeOfForm);
            }
        }

        /// <summary>
        /// 使窗体变得符合子窗体样式
        /// </summary>
        /// <param name="form">需要进行调整得窗体</param>
        private void AdjustForm(Form form)
        {
            form.MdiParent = this;
            form.TopLevel = false;
            form.Dock = DockStyle.Fill;
            form.Parent = this.splitContainer1.Panel2;
            form.Show();
            form.BringToFront();
        }
    }
}
